package object2;


/**
 * 继承练习
 */
public class ExtendsExercise03 {

    public static void main(String[] args) {

        /*
            编写Computer类，包含CPU 内存 硬盘等属性，getDetails()方法用于返回Computer的详细信息
            编写PC子类，继承Computer类，添加特有属性[品牌 brand]
            编写NotePad子类，继承Computer类，添加特有属性[颜色 color]
            编写Test类，在main方法中创建PC和NotePad对象，分别给对象中特有的属性赋值，以及从Computer类继承的属性赋值，并使用方法打印输出信息
         */

        PC pc = new PC("intel","16","500","IBM");
        String info = pc.printInfo();
        System.out.println(info);
    }
}

class Computer {

    String cpu;

    String ram;

    String disk;

    public Computer() {
    }

    public Computer(String cpu, String ram, String disk) {
        this.cpu = cpu;
        this.ram = ram;
        this.disk = disk;
    }

    public String getDetails() {
        return "CPU:" + this.cpu + ",内存:" + this.ram + ",硬盘:" + this.disk;
    }

    public String getCpu() {
        return cpu;
    }

    public void setCpu(String cpu) {
        this.cpu = cpu;
    }

    public String getRam() {
        return ram;
    }

    public void setRam(String ram) {
        this.ram = ram;
    }

    public String getDisk() {
        return disk;
    }

    public void setDisk(String disk) {
        this.disk = disk;
    }
}

class PC extends Computer {

    String brand;

    public PC(String cpu, String ram, String disk, String brand) {
        super(cpu, ram, disk);
        this.brand = brand;
    }

    public String getBrand() {
        return brand;
    }

    public void setBrand(String brand) {
        this.brand = brand;
    }

    public String printInfo() {
        return getDetails() + ",品牌:" + brand;
    }

}

class NotePad extends Computer {

    String color;

    public NotePad(String cpu, String ram, String disk, String color) {
        super(cpu, ram, disk);
        this.color = color;
    }

    public String getColor() {
        return color;
    }

    public void setColor(String color) {
        this.color = color;
    }

    public String printInfo() {
        return getDetails() + ",颜色:" + color;
    }
}


